﻿using System;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MVCBugTracker;
using MVCBugTracker.Controllers;
using MVCBugTracker.Models;
using System.Linq;
using System.Collections.Generic;
using System.Data.Objects.DataClasses;

namespace MVCBugTracker.Tests.Mocks
{
    public class MockData
    {

        #region Project Data
    
        public static List<Project> CreateProjectData()
        {
            List<Project> sampleProjects = new List<Project>();

            for (int i = 0; i < 10; i++)
            {
                Project project = new Project()
                {
                    ProjectID = i,
                    Name = "Project " + i,
                    Description = "Project description " + i,
                    DateCreated = DateTime.Now,
                    Deleted = false
                };

                project.LastUpdate = project.DateCreated;
                project.ProjectMilestones = CreateProjectMilestoneData(project.ProjectID);
                project.ProjectCategories = CreateProjectCategoryData(project.ProjectID);
                project.ProjectPriorities = CreateProjectPriorityData(project.ProjectID);
                project.ProjectStatuses = CreateProjectStatusData(project.ProjectID);
                project.ProjectMembers = CreateProjectMemberData(project.ProjectID);

                sampleProjects.Add(project);
            }

            return sampleProjects;
        }

        private static EntityCollection<ProjectMilestone> CreateProjectMilestoneData(int projectID)
        {
            EntityCollection<ProjectMilestone> milestones = new EntityCollection<ProjectMilestone>();

            for(int i = 1; i <= 5; i++)
            {
                ProjectMilestone milestone = new ProjectMilestone()
                {
                    MilestoneID = i,
                    ProjectID = projectID,
                    Name = "Milestone " + i,
                    ImageUrl = "~/Content/Images/Milestone/" + i + ".gif",
                };
                milestones.Add(milestone);
            }

            return milestones;
        }

        private static EntityCollection<ProjectCategory> CreateProjectCategoryData(int projectID)
        {
            EntityCollection<ProjectCategory> categories = new EntityCollection<ProjectCategory>();

            for (int i = 1; i <= 5; i++)
            {
                ProjectCategory category = new ProjectCategory()
                {
                    CategoryID = i,
                    ProjectID = projectID,
                    Name = "Category " + i
                };
                categories.Add(category);
            }

            return categories;
        }

        private static EntityCollection<ProjectPriority> CreateProjectPriorityData(int projectID)
        {
            EntityCollection<ProjectPriority> priorties = new EntityCollection<ProjectPriority>();

            for (int i = 1; i <= 5; i++)
            {
                ProjectPriority priority = new ProjectPriority()
                {
                    PriorityID = i,
                    ProjectID = projectID,
                    Name = "Priority " + i,
                    ImageUrl = "~/Content/Images/Priority/" + i + ".gif",
                };
                priorties.Add(priority);
            }

            return priorties;
        }

        private static EntityCollection<ProjectStatus> CreateProjectStatusData(int projectID)
        {
            EntityCollection<ProjectStatus> statuses = new EntityCollection<ProjectStatus>();

            for (int i = 1; i <= 5; i++)
            {
                ProjectStatus status = new ProjectStatus()
                {
                    StatusID = i,
                    ProjectID = projectID,
                    Name = "Status " + i,
                    ImageUrl = "~/Content/Images/Status/" + i + ".gif",
                };
                statuses.Add(status);
            }

            return statuses;
        }

        private static EntityCollection<ProjectMember> CreateProjectMemberData(int projectID)
        {
            EntityCollection<ProjectMember> members = new EntityCollection<ProjectMember>();

            for (int i = 1; i <= 5; i++)
            {
                ProjectMember member = new ProjectMember()
                {
                     ID = i,
                    ProjectID = projectID,
                     UserName = "User " + i
                };
                members.Add(member);
            }

            return members;
        }

        #endregion

        #region Bug Data

        public static List<Bug> CreateBugData()
        {
            List<Bug> sampleBugs = new List<Bug>();

            for (int i = 0; i < 30; i++)
            {
                Bug bug = new Bug()
                {
                    BugID = i,
                    ProjectID = 1,
                    Title = "Title " + i,
                    Description = "Bug description " + i,
                    AssignedUserName = "TestUser",
                    CategoryID = 1,
                    PriorityID = 1,
                    StatusID = 1,
                    MilestoneID = 1,
                    DateCreated = DateTime.Now,
                    Deleted = false
                };

                sampleBugs.Add(bug);
            }

            return sampleBugs;
        }

        #endregion
    }
}
